//
//  FriendCircleCommentTestController.m
//  CodeExamples
//
//  Created by letian on 16/12/7.
//  Copyright © 2016年 cmsg. All rights reserved.
//

#import "FriendCircleCommentTestController.h"
#import "FriendCircleModel.h"
#import "FriendCircleCommentView.h"
#import "TestTableViewCell.h"

@interface FriendCircleCommentTestController () <UITableViewDelegate, UITableViewDataSource>

/** <#des#> */
@property (nonatomic,strong) UITableView * tableView;

/** <#des#> */
@property (nonatomic,strong) NSArray * datas;

/** <#des#> */
@property (nonatomic,strong) FriendCircleCommentView * friendCircleCommentView;

@end

@implementation FriendCircleCommentTestController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self labelUI];
//    [self tableViewUI];
    
    [self.view bk_whenTapped:^{
        [self settingLabelUI];
    }];
}

- (void)tableViewUI
{
    [self setupUI];
    [self setConstant];
}

- (void)labelUI
{
    self.friendCircleCommentView = [FriendCircleCommentView new];
    [self.view addSubview:self.friendCircleCommentView];
}

- (void)settingLabelUI
{
    [self.friendCircleCommentView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(100);
        make.left.equalTo(self.view).offset(50);
        make.right.equalTo(self.view).offset(-50);
    }];
    
    NSArray * datas = [FriendCircleModel creatModelsWithCount:10];
    [self.friendCircleCommentView viewDataWithLikeItemsArray:[datas[0] likeDatas] commentItemsArray:[datas[0] commentDatas]];
}

#pragma mark - 设置UI
- (void)setupUI
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView = [LTUITools lt_creatTableViewWithStyle:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[TestTableViewCell class] forCellReuseIdentifier:@"cellId"];
    [self.view addSubview:self.tableView];
}

#pragma mark - 设置约束
- (void)setConstant
{
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(64);
        make.left.right.bottom.equalTo(self.view);
    }];
}

#pragma mark - UITableViewdelegate &&  UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TestTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    [cell cellDataWithModle:self.datas[indexPath.row]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [tableView fd_heightForCellWithIdentifier:@"cellId" cacheByIndexPath:indexPath configuration:^(TestTableViewCell * cell) {
        if (indexPath.row < self.datas.count) {
        [cell cellDataWithModle:self.datas[indexPath.row]];
        }
    }];
}

- (NSArray *)datas
{
    if(!_datas){
        _datas = [FriendCircleModel creatModelsWithCount:10];
    }
    return _datas;
}



@end
